package io.renren.modules.mail.FileUtil;

import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.File;
import java.io.FileInputStream;


public class POIUtil {
    public String ceshi(String path) {
        String substring = path.substring(path.length() - 4, path.length());
        if (substring.contains("docx")) {
            File file = new File(path);
            try{
                FileInputStream fis = new FileInputStream(file);
                XWPFDocument xdoc = new XWPFDocument(fis);
                XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
                String doc1 = extractor.getText();
                fis.close();
                return doc1;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            File file = new File(path);
            try {
                FileInputStream fis = new FileInputStream(file);
                WordExtractor extractor = new WordExtractor(fis);
                String doc1 = extractor.getText();
                fis.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}